import $H from './request.js';
import $C from './config.js';
export default {
	appinit(on) {


		if (!uni.getStorageSync('admin_token')) {
			// uni.navigateTo({
			// 	url: '/pages/index/login'
			// })
		}

		var banmi_plugin = on.query.banmi_plugin

		if (banmi_plugin) {
			document.write('<link rel="stylesheet" href="./static/plugin.css">');
		}


		uni.getSystemInfo({
			success: (res) => {
				var system = res.system;
				var uniPlatform = res.uniPlatform;
				var model = res.model;
				var browserName = res.browserName;

				uni.setStorage({
					key: 'screenWidth',
					data: res.screenWidth
				});
				uni.setStorage({
					key: 'base_url',
					data: $C.baseUrl
				});
				uni.setStorage({
					key: 'system',
					data: system
				});
				uni.setStorage({
					key: 'uniPlatform',
					data: uniPlatform
				});
				uni.setStorage({
					key: 'model',
					data: model
				});
				uni.setStorage({
					key: 'browserName',
					data: browserName
				});
				uni.setStorage({
					key: 'screenHeight',
					data: res.screenHeight
				});
				uni.setStorage({
					key: 'deviceBrand',
					data: res.deviceBrand
				});
				uni.setStorage({
					key: 'brand',
					data: res.brand
				});
				uni.setStorage({
					key: 'appVersion',
					data: res.appVersion
				});
				uni.setStorage({
					key: 'deviceModel',
					data: res.deviceModel
				});
				uni.setStorage({
					key: 'model',
					data: res.model
				});
				uni.setStorage({
					key: 'osAndroidAPILevel',
					data: res.osAndroidAPILevel
				});

				uni.setStorage({
					key: 'romName',
					data: res.romName
				});
				uni.setStorage({
					key: 'romVersion',
					data: res.romVersion
				});
				uni.setStorage({
					key: 'system',
					data: res.system
				});
			}
		})
	},
	GetRequest() {
		let url = window.location.href;
		var theRequest = new Object();
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			var strs = str.split("&");
			for (var i = 0; i < strs.length; i++) {
				theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
			}
		}
		return theRequest;
	},
	is_env() {
		if (process.env.NODE_ENV === 'production') {
			// console.log('正式环境');
			return true;
		} else if (process.env.NODE_ENV === 'development') {
			// console.log('开发环境');
			return false;
		} else {
			// console.log('未知环境');
			return false;
		}
	},
	//登录
	index_login(data) {
		return $H.post('/admin.login/index_login', data);
	},

	//基本信息
	info_ajax(data) {
		return $H.post('/admin.index/admin_info', data);
	},
	//总站点数据统计
	statistics(data) {
		return $H.post('/admin.Statistics/statistics', data);
	},

	Sdetailed(data) {
		return $H.post('/admin.Statistics/detailed', data);
	},
	admin_login_log(data) {
		return $H.post('/admin.Index/admin_login_log', data);
	},
	//应用列表
	Pluginlist_list(data) {
		return $H.post('/admin.Pluginlist/lists', data);
	},
	Pluginlist_pack(data) {
		return $H.post('/admin.Pluginlist/plugin_pack', data);
	},
	//未安装
	Pluginlist_no_list(data) {
		return $H.post('/admin.Pluginlist/no_installed_list', data);
	},
	//插件卸载
	Pluginlist_uninstall(data) {
		return $H.post('/admin.Pluginlist/uninstall', data);
	},
	//插件安装
	Pluginlist_index_Install(data) {
		return $H.post('/admin.Pluginlist/index_Install', data);
	},
	//安装分支
	Pluginlist_Install_branch(data) {
		return $H.post('/admin.Pluginlist/Install_branch', data);
	},
	//插件详情
	Pluginlist_home_index(data) {
		return $H.post('/admin.Pluginlist/home_index', data);
	},
	Pluginlist_set_home(data) {
		return $H.post('/admin.Pluginlist/set_home', data);
	},
	Pluginlist_configuration_plugin(data) {
		return $H.post('/admin.Pluginlist/configuration_plugin', data);
	},
	Article_list(data) {
		return $H.post('/admin.Article/lists', data);
	},
	Article_dels(data) {
		return $H.post('/admin.Article/dels', data);
	},

	Menu_del(data) {
		return $H.post('/admin.Menu/del', data);
	},

	index_index(data) {
		return $H.post('/admin.index/index', data);
	},
	Settings_set_key_limiting(data) {
		return $H.post('/admin.Settings/set_key_limiting', data);
	},
	Settings_set_oss_save(data) {
		return $H.post('/admin.Settings/set_oss_save', data);
	},

	Settings_set_key_sets(data) {
		return $H.post('/admin.Settings/set_key_sets', data);
	},
	Iconpark_index(data) {
		return $H.post('/admin.Iconpark/index', data);
	},

	role_role_list(data) {
		return $H.post('/admin.role/role_list', data);
	},
	role_role(data) {
		return $H.post('/admin.role/role', data);
	},
	admin_admin_add(data) {
		return $H.post('/admin.admin/admin_add', data);
	},
	role_role_del(data) {
		return $H.post('/admin.role/role_del', data);
	},
	role_lists(data) {
		return $H.post('/admin.role/lists', data);
	},
	role_role_edit(data) {
		return $H.post('/admin.admin/role_edit', data);
	},
	role_role_add(data) {
		return $H.post('/admin.role/role_add', data);
	},
	menu_menu_find(data) {
		return $H.post('/admin.menu/menu_find', data);
	},
	admin_menu_list(data) {
		return $H.post('/admin.menu/menu_list', data);
	},
	menu_menu_add(menu_id, data) {
		if (menu_id > 0) {
			var url = '/admin.menu/edit';
		} else {
			var url = '/admin.menu/add';
		}

		return $H.post(url, data);
	},
	Appup_lists(data) {
		return $H.post('/admin.Appup/lists', data);
	},
	Appup_dels(data) {
		return $H.post('/admin.Appup/dels', data);
	},
	Appup_views(data) {
		return $H.post('/admin.Appup/views', data);
	},
	Appup_edit(data) {
		return $H.post('/admin.Appup/edit', data);
	},
	Settings_set_article_find(data) {
		return $H.post('/admin.Settings/set_article_find', data);
	},
	Settings_set_article_edit(data) {
		return $H.post('/admin.Settings/set_article_edit', data);
	},
	admin_admin_del(data) {
		return $H.post('/admin.admin/admin_del', data);
	},
	admin_admin_finds(data) {
		return $H.post('/admin.admin/admin_finds', data);
	},
	pluginlist_add_plugin(data) {
		return $H.post('/admin.pluginlist/add_plugin_uniapp', data);
	},
	pluginlist_plugin_testing(data) {
		return $H.post('/admin.pluginlist/plugin_testing', data);
	},
	pluginlist_zip_plugin(data) {
		return $H.post('/admin.pluginlist/zip_plugin', data);
	},
	user_index(data) {
		return $H.post('/admin.user/index', data);
	},
	user_user_state(data) {
		return $H.post('/admin.user/user_state', data);
	},
	user_user_info(data) {
		return $H.post('/admin.user/user_info', data);
	},
	user_user_add(uid, data) {
		if (uid > 0) {
			var url = '/admin.user/edit';
		} else {
			var url = '/admin.user/add';
		}
		return $H.post(url, data);
	},
	user_edit_money(data) {
		return $H.post('/admin.Usermoney/edit_money', data);
	},
	user_login_log(data) {
		return $H.post('/admin.UsersloginLog/index_user_login_log', data);
	},
	user_money_log(data) {
		return $H.post('/admin.Usersmoneylog/user_money_log', data);
	},
	user_reg_info(data) {
		return $H.post('/admin.Usersreg/index_user_reg_info', data);
	},
	Wechatsreply_reply_list(data) {
		return $H.post('/admin.Wechatsreply/reply_list', data);
	},
	Wechatsreply_reply_del(data) {
		return $H.post('/admin.Wechatsreply/reply_del', data);
	},
	Wechatsreply_reply_del(data) {
		return $H.post('/admin.Wechatsreply/reply_del', data);
	},
	Wechatsreply_reply_state(data) {
		return $H.post('/admin.Wechatsreply/reply_state', data);
	},
	Wechatsreply_reply_add(data) {
		return $H.post('/admin.Wechatsreply/reply_add', data);
	},
	Wechatsreply_set_wechats_init(data) {
		return $H.post('/admin.DeveloperWechats/set_wechats_init', data);
	},
	Wechatsreply_set_wechats_menu(data) {
		return $H.post('/admin.DeveloperWechats/set_wechats_menu', data);
	},
	Wechatsreply_set_wechats_menu_post(data) {
		return $H.post('/admin.DeveloperWechats/set_wechats_menu_post', data);
	},
	DeveloperWechats_index(data) {
		return $H.post('/admin.DeveloperWechats/index', data);
	},
	DeveloperWechats_weixin_set_key(data) {
		return $H.post('/admin.DeveloperWechats/weixin_set_key', data);
	},
	DeveloperWechats_weixin_set_token(data) {
		return $H.post('/admin.DeveloperWechats/weixin_set_token', data);
	},
	DeveloperWechats_save(data) {
		return $H.post('/admin.DeveloperWechats/save', data);
	},
	menu_menu_index(data) {
		return $H.post('/admin.menu/menu_index', data);
	},
	Configurationtemplate_index(data) {
		return $H.post('/admin.Configurationtemplate/index', data);
	},
	Configurationtemplate_save(data) {
		return $H.post('/admin.Configurationtemplate/save', data);
	},

	Pluginlist_index_branch_Install(data) {
		return $H.post('/admin.Pluginlist/index_branch_Install', data);
	},
	Upload_aattachment_group_grouping(data) {
		return $H.post('/admin.Upload/aattachment_group_grouping', data);
	},
	Upload_locality_attachment_group_del(data) {
		return $H.post('/admin.Upload/locality_attachment_group_del', data);
	},
	Upload_locality_attachment_group_edit(data) {
		return $H.post('/admin.Upload/locality_attachment_group_edit', data);
	},
	Upload_locality_attachment_group_add(data) {
		return $H.post('/admin.Upload/locality_attachment_group_add', data);
	},
	Upload_locality_attachment_list(data) {
		return $H.post('/admin.Upload/locality_attachment_list', data);
	},
	Upload_locality_attachment_wx_img_del(data) {
		return $H.post('/admin.Upload/locality_attachment_wx_img_del', data);
	},
	Upload_locality_attachment_name_edit(data) {
		return $H.post('/admin.Upload/locality_attachment_name_edit', data);
	},
	Upload_attachment_list(data) {
		return $H.post('/admin.Upload/attachment_list', data);
	},
	Upload_attachment_name_edit(data) {
		return $H.post('/admin.Upload/attachment_name_edit', data);
	},
	Upload_aattachment_group_add(data) {
		return $H.post('/admin.Upload/aattachment_group_add', data);
	},
	Upload_aattachment_wx_group_grouping(data) {
		return $H.post('/admin.Upload/aattachment_wx_group_grouping', data);
	},
	Upload_attachment_wx_img_del(data) {
		return $H.post('/admin.Upload/attachment_wx_img_del', data);
	},
	Mysql_set_bale(data) {
		return $H.post('/admin.Mysql/set_bale', data);
	},
	Settings_set_admin_find(data) {
		return $H.post('/admin.Settings/set_admin_find', data);
	},
	Settings_set_admin_pwa(data) {
		return $H.post('/admin.Settings/set_admin_pwa', data);
	},


	PW_mysql_init_ajax() {
		let requestParams = {
			id: 1,
		};
		return $H.post('/admin.Mysql/init', requestParams);

	},

	PW_mysql_full_ajax(table) {
		return new Promise((res, rej) => {
			let requestParams = {
				table: table,
			};
			$H.post('/admin.Mysql/query_full', requestParams).then(ret => {
				var find = ret.data;
				res(find);
			})
		});
	},
	upgrade_api(data) {
		return $H.post('/admin.Pluginlist/upgrade_api', data);
	},
	plugin_down(data) {
		return $H.post('/admin.Pluginlist/download_plugin', data);
	},

	plugin_down_size(data) {
		return $H.post('/admin.Pluginlist/detection_size', data);
	},
	plugin_part_down(data) {
		return $H.post('/admin.Pluginlist/part_down', data);
	},
	plugin_part_merge(data) {
		return $H.post('/admin.Pluginlist/part_merge', data);
	},
	plugin_api_shop(data) {
		return $H.post('/admin.Pluginlist/api_shop', data);
	},
	plugin_get_detection(data) {
		return $H.post('/admin.Pluginlist/get_detection', data);
	},
	get_info(data) {
		return $H.post('/admin.Index/get_info', data);
	},
	getUrlParams() {
		let url = window.location.href;
		const reg = /(\w+)=([^&]+)/g;
		const params = {};
		let match;

		while ((match = reg.exec(url)) !== null) {
			params[match[1]] = match[2];
		}
		return params;
	}
}